﻿using OpenTelemetry.Trace;

namespace iPanel.Otlp;

public class CustomExcludingSampler : Sampler
{
    //private readonly Sampler innerSampler = new AlwaysOnSampler();
    //string[] ignoreTraces = { "/_framework", "/opentelemetry.proto", "/_content" };

    public override SamplingResult ShouldSample(in SamplingParameters samplingParameters)
    {
        return new SamplingResult(SamplingDecision.Drop);
        //// 检查是否为 gRPC 调用
        //if (IsIgnore(samplingParameters.Tags))
        //{
        //    return new SamplingResult(SamplingDecision.Drop);
        //}

        //// 非 gRPC 调用，使用内部采样器进行决策
        //return innerSampler.ShouldSample(samplingParameters);
    }

    //private bool IsIgnore(IEnumerable<KeyValuePair<string, object>>? attributes)
    //{
    //    if (attributes is null) return false;
    //    foreach (var attribute in attributes)
    //    {
    //        if (attribute.Key == "rpc.system" && attribute.Value is string system && system == "grpc")
    //        {
    //            return true;
    //        }
    //    }
    //    return false;
    //}
}
